home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / utility / fortn608.zip / FORTUNE.DOC < prev    next >
Text File  |  1996-08-31  |  23KB  |  502 lines

  1. FORTUNE.DOC                          1                         Revised: 08-31-96
  2.  
  3. The FORTUNE.EXE program adds some tuning features to the DOS  FOR  command  (FOR
  4. tune, fortune, what the heck).  These features can in some  way  be  applied  to
  5. commands accepting regular DOS wildcards.  Features include:
  6.  
  7.  * Results of command are written to a batch file which you can review before
  8.    you run it.  Lets you subsequently edit it if desired and lets you see
  9.    exactly what commands will happen when you run it.
  10.  * You can also try the commands interactively if they don't require that
  11.    much memory to run.
  12.  * Ability to embed redirection indicators in a command (see next example).
  13.  * Ability to separate the file name and file extension.  For example:
  14.         FORTUNE IN (*.TXT) DO SORT %[ %A %] %1*.SOR
  15.  * Ability to identify individual characters in the the file name and extension.
  16.    For example:
  17.         FORTUNE IN (*.TXT) DO RENAME %A (%1%2%3%4%5%6).*
  18.  * Ability to specify a character other than "%" for the delimiter so you can
  19.    avoid worrying about different syntax in batch command vs command line.
  20.  * Ability to have batch file pause after each command so results can be
  21.    reviewed.
  22.  * Ability to specify incrementation in the file names.  For example:
  23.         FORTUNE IN (*.TXT) /+2 DO COPY %A %1*.%0001
  24.  * Ability to specify multiple statements on one command line.
  25.  * Ability to process children subdirectories (/S option) at same time.  For
  26.    example:
  27.         FORTUNE IN (\*.TXT) /S DO COPY %A D:\BACKUPS
  28.         FORTUNE *.BAT /S DEL %A
  29.  * Ability to exclude up to 10 file specifications from consideration.
  30.  * Ability to do those tough PKZIP commands that you always wanted to do.  Like
  31.    compress all *.FLI files in your subdirectory to a ZIP of the same name as
  32.    the original file:
  33.         FORTUNE *.FLI /DO PKZIP -M %R %e
  34.    Or move all WAV files into ZIP files with the same name as the WAV file
  35.    (separate ZIP for each WAV file):
  36.         FORTUNE *.WAV PKZIP -M %R %R.%E
  37.  * In addition, you can use the command to create a file which contains a
  38.    series of commands including a header and footer section which can be used
  39.    for some batch functions.
  40.  
  41.  
  42. The DOS FOR command:
  43.  
  44. Quite a few DOS users are unaware of the DOS FOR command.  It allows you to do a
  45. single command over a series of files and provides an easy way to use  wildcards
  46. with commands that don't accept them.  For example, if you want to type a number
  47. of files to your screen, you can say something like:
  48.  
  49.         FOR %A IN (*.TXT) DO TYPE %A
  50.  
  51. DOS looks at your IN specification and figures out what file names  are  covered
  52. by that request.  The request can include path information if  desired  and  can
  53. have multiple specification (e.g.  "...IN (*.TXT \BAT\*.DOC)...").
  54.  
  55. FOR then substitutes the file name itself in for whatever variable  you  specify
  56. in the first parameter after "FOR" ("%A"  here).   This  variable  is  a  single
  57. character (A to Z) preceded by a single percent sign (%).  (If FOR is used in  a
  58. batch command, you have to use two percent signs (%%) instead.)
  59.  
  60.  
  61. FORTUNE.DOC                          2                         Revised: 08-31-96
  62.  
  63. FOR then looks at the command following  the  keyword  "DO"  and  executes  that
  64. command.  If it finds the variable name in the command, it substitutes the  name
  65. of the file for that variable.
  66.  
  67. So, in the above example, if you had three *.TXT files--ABLE.TXT, BAKER.TXT, and
  68. CHARLIE.TXT--and you ran the command, it would actually do  three  commands  for
  69. you:
  70.  
  71.         TYPE ABLE.TXT
  72.         TYPE BAKER.TXT
  73.         TYPE CHARLIE.TXT
  74.  
  75. All in all, FOR is a *very* useful command.  There are also some DOS tricks that
  76. you can use to make the command even more useful but, frankly, I  always  forget
  77. the tricks.  (If someone would like to e-mail them to me,  I'll  throw  them  in
  78. here.) In any case, even past the tricks, the FORTUNE command provides even more
  79. features.
  80.  
  81.  
  82. FORTUNE wildcards and special characters:
  83.  
  84. The FORTUNE.EXE program extends the functionality of  the  DOS  FOR  command  by
  85. providing ways of splitting up the parts of the file name and  manipulating  the
  86. parts.  For example, someone in my office had a mess of files  that  had  to  be
  87. renamed as an open parenthesis, followed by the first six characters of the file
  88. name, followed by a close parenthesis.  Not too terrible to handle with my  text
  89. editor but it hadn't occurred to her.  Using FORTUNE, however, it's pretty easy:
  90.  
  91.         FORTUNE IN (*.TXT) DO RENAME %A (%1%2%3%4%5%6).*
  92.  
  93. And then you run the newly-created batch file (DOIT.BAT).
  94.  
  95. Similarly, someone wanted me to rename a mess of files so  they  had  sequential
  96. names.  I  had  to  write  a  program  to  handle  it.   Definitely  beyond  his
  97. capabilities.  Again, using FORTUNE it's pretty easy:
  98.  
  99.         FORTUNE IN *.TXT DO RENAME %A %1*.%0001
  100.  
  101. And again you run the DOIT.BAT file.
  102.  
  103. Within the command (DO command), FORTUNE allows  you  to  include  a  number  of
  104. indicators.  The character which indicates that  it's  a  special  character  is
  105. typically "%" but you can change this with the /VAR=char option in FORTUNE.  All
  106. of the examples here use the default /VAR=% setting.
  107.  
  108. NOTE TO 4DOS USERS:  4DOS automatically translates %x characters even if used on
  109. the command line.  As such, 4DOS users *have* to use a different /VAR=x  setting
  110. to use FORTUNE.  FORTUNE detects that you are running 4DOS and typically changes
  111. the default /VAR=% to /VAR=@.
  112.  
  113.  
  114. FORTUNE.DOC                          3                         Revised: 08-31-96
  115.  
  116. In many cases, the indicators are case sensitive; there's a  difference  between
  117. %p and %P (presuming the default /VAR=% delimiter).   Typically,  the  lowercase
  118. variants are cumulative.  %P gives you just the path whereas %p  throws  in  the
  119. drive information too.
  120.  
  121.      %a         translates into the entire file name (begins with drive,
  122.                 colon, \, path, \, file root, ., file extension).
  123.                 Use %R.%E if you want the filename without the drive/path info
  124.      %D         translates into the drive (not followed by :)
  125.      %d         translates into the drive (followed by :)
  126.      %P         translates into path (not preceded or followed by \)
  127.      %p         translates into path (begins with drive, colon, \, path, \)
  128.      %R         translates into file name root
  129.      %r         translates into file name root (begins with drive, colon, \,
  130.                 path, \)
  131.      %E         translates into file name extension
  132.      %e         translates into file name extension (begins with drive, colon,
  133.                 \, path, \, file name root, .)--same as %a
  134.      %1 to %8   characters 1 to 8 in the file name root
  135.      %X to %Z   characters 1 to 3 in file name extension (case insignificant;
  136.                 %X is the same as %x)
  137.       %*        replaces the character with the standard "*" wildcard
  138.       %?        replaces the character with the standard "?" wildcard
  139.  
  140. Unless preceded by the /VAR=x delimiter, the  standard  DOS  wildcards--"*"  and
  141. "?"--are supported within the file name.  "...DO RENAME %A Q*.Y*" will  actually
  142. generate commands with the letters filled in (if the file  name  is  APPLES.ARE,
  143. the command will be RENAME QPPLES.YRE).
  144.  
  145. If you want to actually write out the commands and  leave  in  the  "*"  or  "?"
  146. characters, precede the characters with "%" or whatever.  For example,  "FORTUNE
  147. (*.001) DO COPY %R.0%* %R.TOP" will generate something  like  "COPY  TN960402.0*
  148. TN960402.TOP" whereas "FORTUNE (*.001) DO COPY %R.0* %R.TOP" will generate "COPY
  149. TN960402.001 TN960402.TOP".
  150.  
  151. All other characters in the command string are passed as given.
  152.  
  153.  
  154. FORTUNE.DOC                          4                         Revised: 08-31-96
  155.  
  156. Using  the  above  characters,  if  you  have  two  files  C:\AUTOEXEC.BAT   and
  157. D:\WAYNE\MYSTUFF.TXT, the various codes above translate as:
  158.  
  159.                 C:\AUTOEXEC.BAT         D:\WAYNE\MYSTUFF.TXT
  160.      %A         C:\AUTOEXEC.BAT         D:\WAYNE\MYSTUFF.TXT
  161.      %D         C